package com.young.mybatis.v2.sqlnode;

import com.young.mybatis.v2.sqlnode.iface.SqlNode;
import com.young.utils.OgnlUtils;

/**
 * 描述:封装if标签的sql信息
 *
 * @author BluceYoung
 * @create 2020-07-04 9:37
 * B站：TeacherYoung凌风
 * www.teacheryoung.com
 */
public class IfSqlNode implements SqlNode {
    private String test;

    private SqlNode rootSqlNode;

    public IfSqlNode(String test, SqlNode rootSqlNode) {
        this.test = test;
        this.rootSqlNode = rootSqlNode;
    }

    public void apply(DynamicContext context) {
        Object parameter = context.getBindings().get("_parameter");
        boolean evaluateBoolean = OgnlUtils.evaluateBoolean(test, parameter);
        if(evaluateBoolean){//条件为true，继续递归解析子节点
            rootSqlNode.apply(context);
        }
    }
}
